<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('姓名')">
              <a-input :placeholder="$t('请输入姓名')" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('手机号')">
              <a-input :placeholder="$t('请输入手机号')" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务员类型')">
                <j-dict-select-tag
                  :placeholder="$t('请选择业务员类型')"
                  v-model="queryParam.type"
                  dictCode="bis_salesman.type"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'BisSalesmanController:add'">{{ $t('新增') }}</a-button>
      <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('业务员'))" v-has="'BisSalesmanController:export'">{{
        $t('导出')
      }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'BisSalesmanController:edit'">{{ $t('编辑') }}</a>
          <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)" style="margin-left: 8px">
            <a v-has="'BisSalesmanController:delete'">{{ $t('删除') }}</a>
          </a-popconfirm>
          <a @click="handleQr(record)" style="margin-left: 8px">{{ $t('推广码') }}</a>
        </span>
      </a-table>
    </div>

    <bis-salesman-modal ref="modalForm" @ok="modalFormOk"></bis-salesman-modal>
    <!-- <qrcode-modal ref="qrmodalForm" @ok="modalFormOk"></qrcode-modal> -->
    <a-modal
      class="modal_title"
      :title="$t('推广码')"
      :visible="qrVisible"
      @cancel="handleCancel"
      :cancel-text="$t('关闭')"
    >
      <qrcode-modal
        v-if="qrVisible"
        :info="info"
        :param="'id'"
        :paramValue="'id'"
        :url="'/device/bisDeviceInfo/qrCodeImg'"
      ></qrcode-modal>
      <template slot="footer">
        <a-button type="default" @click="handleCancel">{{ $t('关闭') }}</a-button>
      </template>
    </a-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BisSalesmanModal from './modules/BisSalesmanModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import QrcodeModal from './modules/QrcodeModal'

export default {
  name: 'BisSalesmanList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BisSalesmanModal,
    QrcodeModal,
  },
  data() {
    return {
      description: '业务员管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: this.$t('业务员类型'),
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('绑定会员手机号'),
          align: 'center',
          dataIndex: 'memberInfoDictEntityPhone',
          customRender: (t, r)=> {
            if (r.memberInfoDictEntity && r.memberInfoDictEntity.length>0 && r.memberInfoDictEntity[0].phone) {
              return r.memberInfoDictEntity[0].phone
            }
            return ''
          },
        },
        {
          title: this.$t('绑定会员姓名'),
          align: 'center',
          dataIndex: 'memberInfoDictEntity',
          customRender: function (t, r) {
            if (t && t.length>0 && t[0].name) {
              return t[0].name
            }
            return ''
          },
        },
        {
          title: this.$t('绑定系统用户名'),
          align: 'center',
          dataIndex: 'userId_dictText',
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('添加时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/member/bisSalesman/list',
        delete: '/member/bisSalesman/delete',
        deleteBatch: '/member/bisSalesman/deleteBatch',
        exportXlsUrl: '/member/bisSalesman/exportXls',
        importExcelUrl: 'member/bisSalesman/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      qrVisible: false,
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: this.$t('姓名'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'phone', text: this.$t('手机号'), dictCode: '' })
      fieldList.push({ type: 'int', value: 'type', text: this.$t('业务员类型'), dictCode: 'bis_salesman.type' })
      fieldList.push({
        type: 'string',
        value: 'memberId',
        text: this.$t('绑定会员'),
        dictCode: 'bis_member_info,name,id',
      })
      fieldList.push({
        type: 'string',
        value: 'userId',
        text: this.$t('绑定系统用户'),
        dictCode: 'sys_user,realname,id',
      })
      fieldList.push({ type: 'int', value: 'state', text: this.$t('状态'), dictCode: 'bis_salesman.state' })
      this.superFieldList = fieldList
    },
    handleQr(record) {
      this.qrVisible = true
      this.info = record
      // this.$refs.qrmodalForm.qrCode(item)
    },
    handleCancel() {
      this.qrVisible = false
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>